package com.rf.richfitwheel.admin.sys.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import com.rf.richfitwheel.admin.contants.UrlConstant;
import com.rf.richfitwheel.admin.sys.model.SysStationProcessConfig;
import com.rf.richfitwheel.admin.sys.service.SysStationProcessConfigService;
import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 组织与岗位关系表
 *
 * @author zhanglu
 * @email zhanglu2@cnpc.com.cn
 * @date 2021-06-08 08:39:52
 */
@RestController
@RequestMapping(UrlConstant.WEB_ADMIN_URL + "/stationProcessConfig")
public class SysStationProcessConfigController {
    private static Logger log = LoggerFactory.getLogger(SysStationProcessConfigController.class);

    @Autowired
    private SysStationProcessConfigService sysStationProcessConfigService;

    /**
     * 列表
     */
    @GetMapping("/queryList")
    //@RequiresPermissions("generator:sysstationprocessconfig:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = null;
        try {
            page = sysStationProcessConfigService.queryPage(params);
        } catch (IOException e) {
            log.error("无法解析参数", e);
            return R.error("无法解析参数");
        }

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("generator:sysstationprocessconfig:info")
    public R info(@PathVariable("id") String id) {
        SysStationProcessConfig sysStationProcessConfig = sysStationProcessConfigService.selectById(id);

        return R.ok().put("sysStationProcessConfig", sysStationProcessConfig);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("generator:sysstationprocessconfig:save")
    public R save(@RequestBody SysStationProcessConfig sysStationProcessConfig) {
        //sysStationProcessConfigService.save(sysStationProcessConfig);
        if (sysStationProcessConfig.getId() == null || "".equals(sysStationProcessConfig.getId())) {
            //新增
            sysStationProcessConfigService.addSysStationProcessConfig(sysStationProcessConfig, UserUtil.getUser());
        } else {
            //修改
            sysStationProcessConfigService.updateSysStationProcessConfig(sysStationProcessConfig, UserUtil.getUser());
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("generator:sysstationprocessconfig:update")
    public R update(@RequestBody SysStationProcessConfig sysStationProcessConfig) {
        //sysStationProcessConfigService.updateById(sysStationProcessConfig);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("generator:sysstationprocessconfig:delete")
    public R delete(@RequestBody String[] ids) {
        //sysStationProcessConfigService.removeByIds(Arrays.asList(ids));
        try {
            sysStationProcessConfigService.deleteBatch(ids);
            return R.ok();
        } catch (Exception e) {
            log.error("删除岗位流程失败", e);
            return R.error("删除岗位流程失败");
        }
    }

}
